#include <bits/stdc++.h>
using namespace std;

// #define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
	{                                         \
		cerr << "\033[32;1m" << #x << " -> "; \
		err(x);                               \
	}
void err()
{
	cerr << "\033[39;0m" << endl;
}
template <typename T, typename... A>
void err(T a, A... x)
{
	cerr << a << ' ';
	err(x...);
}
#else
#define dbg(...)
#endif

typedef long long LL;

const int N = 1e4 + 50, M = 1e3 + 50,
		  INF = 0x3f3f3f3f;

int dp[N << 1][M << 1];

char sa[N], sb[M];
// int a[N], b[N];
char a[N << 1], b[M << 1];
inline void update(int &a, int b)
{
	a = min(a, b);
}

int extend(char sa[], char a[], int n, int &ans)
{
	int res = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (isalpha(sa[i]))
			a[++res] = sa[i];
		else
		{
			++ans;

			for (int j = 0; j < sa[i] - '0'; ++j)
				a[++res] = '*';
		}
	}
	return res;
}

int main(int argc, char const *argv[])
{
	memset(dp, 0x3f3f3f3f, sizeof(dp));
	scanf("%s%s", sa + 1, sb + 1);
	int n = strlen(sa + 1), m = strlen(sb + 1);
	// dbg(n, m);
	dp[0][0] = 0;
	int ans = 0;
	n = extend(sa, a, n, ans);
	m = extend(sb, b, m, ans);
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= m; ++j)
		{
			if (i + j == 0)
				continue;
			if (i > 0)
				update(dp[i][j], dp[i - 1][j] + 1);
			if (j > 0)
				update(dp[i][j], dp[i][j - 1] + 1);
			if (i > 0 && j > 0)
				if (a[i] == b[j] || a[i] == '*' || b[j] == '*')
					update(dp[i][j], dp[i - 1][j - 1]);
		}

	printf("%d\n", dp[n][m] + ans);
	return 0;
}